package com.financing.platform.dao.impl;


import java.sql.SQLException;
import java.util.Collections;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.financing.platform.dao.IFaUserVisitDao;
import com.financing.platform.dto.FaUserVisitDTO;
import com.financing.platform.util.SqlName;
import com.financing.platform.vo.FaUserVisitStatisticVO;

@Repository("faUserVisitDaoImpl")
public class FaUserVisitDaoImpl extends BaseDaoImpl  implements IFaUserVisitDao {

	public int addFaUserVisit(FaUserVisitDTO faUserVisitDTO)
			throws SQLException {
		return (Integer) this.sqlMapClient.insert(SqlName.addVisit, faUserVisitDTO);
	}

	@SuppressWarnings("unchecked")
	public List<FaUserVisitDTO> queryFaUserVisit(FaUserVisitDTO faUserVisitDTO) {
		try {
			return this.sqlMapClient.queryForList(SqlName.queryVisit,faUserVisitDTO);
		} catch (SQLException e) {
			log.error("query fa user visit error!",e);
			return Collections.emptyList();
		}
	}

	@Override
	public FaUserVisitStatisticVO queryFaUserVisitStatistic(String faId)throws SQLException {
		FaUserVisitStatisticVO bean = (FaUserVisitStatisticVO) this.sqlMapClient.queryForObject(SqlName.queryFaUserVisitStatistic,faId);
		return bean==null?new FaUserVisitStatisticVO():bean;
	}

	@Override
	public String queryFaIdByLoginName(String loginName) throws SQLException {
		return (String)this.sqlMapClient.queryForObject(SqlName.queryFaIdByLoginName,loginName);
	}

	@Override
	public void updateLastVisitTime(FaUserVisitDTO faUserVisitDTO) throws SQLException {
		this.sqlMapClient.update(SqlName.updateLastVisitTime, faUserVisitDTO);
	}

	
}
